<?php
	// no direct access
	defined( '_JEXEC' ) or die( 'Restricted access' );
	jimport('joomla.application.component.controller');

	class DivisionController extends JController
	{
		/**
		 * Method to display the view
		 *
		 * @access    public
		 */
		function display()
		{
			$document =& JFactory::getDocument();
			
			$view = & $this->getView('divisionlist', $document->getType());
			
			if ($model = & $this->getModel('division')) 
			{
				$view->setModel($model, true);
			}                         			
			
			$view->display();
		}
		
		function edit()
		{
			if($cids === null)
			{
                JError::raiseError(500, 'cid parameter missing from the request');
			}		
		
			$document =& JFactory::getDocument();
			
			$view = & $this->getView('divisionedit', $document->getType());
			
			if ($model = & $this->getModel('division')) 
			{
				$view->setModel($model, true);
			}                         			
			
			$view->display();  
		}
		
		function save()
		{
			$division = JRequest::get('POST');
       
			$model = & $this->getModel('division'); 
			$model->saveDivision($division);
       
			$redirectTo = JRoute::_('index.php?option='.JRequest::getVar('option'));
			$this->setRedirect($redirectTo, 'Division Saved!');             
		}
		
		function add()
		{
			$document =& JFactory::getDocument();
			
			$view = & $this->getView('divisionadd', $document->getType());
			
			if ($model = & $this->getModel('division')) 
			{
				$view->setModel($model, true);
			}                         			
			
			$view->display();		
		}
		
		function remove()
		{
             $ids = JRequest::getVar('cid', null, 'default', 'array' ); 
         
             if($ids === null)
			 { 
                   JError::raiseError(500, 'cid parameter missing from the request');
             }
         
             $model = & $this->getModel('division');
             $model->deleteDivisions($ids);
         
             $redirectTo = JRoute::_('index.php?option='.JRequest::getVar('option'));
             $this->setRedirect($redirectTo, 'Division Deleted!');                
         }		
	}
?>